package com.yiyuplatform.service.user.impl;

import com.yiyuplatform.entity.TUserinfo;
import com.yiyuplatform.repository.TUserInfoRepository;
import com.yiyuplatform.service.user.UserInfoService;
import com.yiyuplatform.vo.DataVO;
import com.yiyuplatform.vo.UserInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: Drew
 * @Date: 2021/10/28 11:29
 * @Description: UserInfoService接口实现
 */
@Service
@Slf4j
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private TUserInfoRepository tUserInfoRepository;

    @Override
    public DataVO findDataVO() {
        DataVO dataVO = new DataVO();
        // 先查TUserInfo表
        List<TUserinfo> tUserinfoList = tUserInfoRepository.findAll();
        // 转为VO 写法1
//        List<WechatAccountVO> wechatAccountVOList=new ArrayList<>();
//        for(TUserinfo tUserinfo : tUserinfoList){
//            WechatAccountVO wechatAccountVO=new WechatAccountVO();
//            wechatAccountVO.setCiId(tUserinfo.getCiId());
//            wechatAccountVO.setCiNkname(tUserinfo.getCiNkname());
//        }
//        写法2 使用stream流
        List<UserInfoVO> userInfoVOList = tUserinfoList.stream()
                .map(e -> new UserInfoVO(
                        e.getCiId(),
                        e.getCiNkname(),
                        e.getCiPhonenumber(),
                        e.getCiIdCard(),
                        e.getCiProfile(),
                        e.getCiPersontype(),
                        e.getCiLevel()
                )).collect(Collectors.toList());
        // 装载到dataVO
        dataVO.setUserInfoVOS(userInfoVOList);
        return dataVO;
    }
}
